// import React from 'react'
import React, { useState, useEffect } from 'react'

import { Switch, Route, Redirect } from 'react-router-dom';
import List from './List'
import Add from './Add'
import Edit from './Edit'

function Default(props) {
    const baseUrl = props.match.path; // /manage/interview

    const Url = props.location.pathname.split('/');
    // console.log("props.match.path",Url);
    // const [url,setUrl]=useState('/hot')
    // setUrl(function(){
    //     return props.location.pathname.split('/')[3]
    // })
    let addUrl
    let editUrl
    let TvUrl
    if (Url[3] === 'add') {
        addUrl = Url[3]
    } else if (Url[4] === 'edit') {
        editUrl = Url[4]
        console.log("editUrl",editUrl);
    } else {
        TvUrl = Url[3]
    }

    return (
        <div>
            <Switch>
                {/* <Route path={Url[3]!='add'?baseUrl + '/'+Url[3]:baseUrl + "/add"} component={List}  /> */}
                <Route path={baseUrl + "/" + TvUrl} component={List} />
                <Route path={baseUrl + "/" + addUrl} component={Add} />
                {/* <Route path={Url[3]!='add'?baseUrl+ '/'+Url[3] + "/edit/:doubanId":baseUrl + "/add"} component={Edit} /> */}
                <Route path={baseUrl + "/"+Url[3]+"/" + editUrl + "/:doubanId"} component={Edit} />
                <Redirect exact from={baseUrl} to={baseUrl + '/hot'} />
            </Switch>
        </div>
    )
}

export default Default;